package com.biyao.service.model.base.imp;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;

import com.biyao.schedulingdao.base.TBearingBoxTypeMapper;
import com.biyao.schedulingentity.base.TBearingBoxEntity;
import com.biyao.schedulingentity.base.TBearingBoxTypeEntity;
import com.biyao.service.model.base.TBearingBoxTypeMessage;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;
/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:08
 */
@Service
public class TBearingBoxTypeService extends ServiceImpl<TBearingBoxTypeMapper, TBearingBoxTypeEntity> implements TBearingBoxTypeMessage {

    public Page list(int pageNum, int pageSize){

        EntityWrapper<TBearingBoxTypeEntity> tBearingBoxTypeentityWrapper=new EntityWrapper<>();
        Page page=selectPage(new Page(pageNum,pageSize),tBearingBoxTypeentityWrapper);
        page.setRecords(formatRecords(page.getRecords()));
        return page;
    }

    List formatRecords(List<TBearingBoxTypeEntity> list){
        List resList=new ArrayList();
        for(TBearingBoxTypeEntity tBearingBoxTypeEntity:list){
            Map map=formatEntity(tBearingBoxTypeEntity);
            resList.add(map);
        }
        return resList;
    }

    Map formatEntity(TBearingBoxTypeEntity tBearingBoxTypeEntity){
        Map map=new HashMap(16);
        //轴承箱型号
        if(tBearingBoxTypeEntity.getId()!=null){
           map.put("id",tBearingBoxTypeEntity.getId());
        }
        //代号
        if(tBearingBoxTypeEntity.getCode()!=null){
           map.put("code",tBearingBoxTypeEntity.getCode());
        }
        //名字
        if(tBearingBoxTypeEntity.getName()!=null){
           map.put("name",tBearingBoxTypeEntity.getName());
        }
        //
        if(tBearingBoxTypeEntity.getRemark()!=null){
           map.put("remark",tBearingBoxTypeEntity.getRemark());
        }
        //
        if(tBearingBoxTypeEntity.getCreateTime()!=null){
           map.put("createTime",tBearingBoxTypeEntity.getCreateTime());
        }
        //
        if(tBearingBoxTypeEntity.getUpdateTime()!=null){
           map.put("updateTime",tBearingBoxTypeEntity.getUpdateTime());
        }
        //
        if(tBearingBoxTypeEntity.getCreateBy()!=null){
           map.put("createBy",tBearingBoxTypeEntity.getCreateBy());
        }
        //
        if(tBearingBoxTypeEntity.getUpdateBy()!=null){
           map.put("updateBy",tBearingBoxTypeEntity.getUpdateBy());
        }
        return map;
    }

    @Override
    public TBearingBoxTypeEntity selectBearingBox(Integer id) {
        return selectById(id);
    }

    @Override
    public Boolean selectCodeIsRepeat(String code) {
        EntityWrapper<TBearingBoxTypeEntity> tBearingBoxTypeentityWrapper=new EntityWrapper<>();
        tBearingBoxTypeentityWrapper.eq("code",code);
        List<TBearingBoxTypeEntity> list=selectList(tBearingBoxTypeentityWrapper);
        if(list.size()>0){
            return true;
        }
        return false;
    }


    public Boolean selectUpdateCodeIsRepeat(String code,Integer id) {
        EntityWrapper<TBearingBoxTypeEntity> tBearingBoxTypeentityWrapper=new EntityWrapper<>();
        tBearingBoxTypeentityWrapper.eq("code",code);
        List<TBearingBoxTypeEntity> list=selectList(tBearingBoxTypeentityWrapper);
        if(list.size()>0){
            if(list.get(0).getId().intValue()!=id.intValue()){
                return true;
            }
            return false;
        }
        return false;
    }
}

